package cn.neusoft.controller;

import cn.neusoft.pojo.Employee;
import cn.neusoft.query.BaseQuery;
import cn.neusoft.query.EmployeeQuery;
import cn.neusoft.service.IEmployeeService;
import cn.neusoft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/emp")
public class EmployController {
	@Autowired
	private IEmployeeService employeeService;
	@PostMapping
	public ResultBean save(@RequestBody Employee employee) throws Exception {
		System.out.println("添加操作");
		System.out.println(employee);
		if(employee.getEmpno()==null) {
			return employeeService.add(employee);
		}
		return employeeService.update(employee);
	}
	@DeleteMapping ("/{id}")
	public ResultBean delete(@PathVariable("id") Integer id) throws Exception {
		System.out.println("删除操作");
		return employeeService.delete(id);
	}
	@GetMapping("/all")
	public ResultBean all(@PathVariable("id") Integer id) throws Exception {
		System.out.println("删除操作");
		return employeeService.getAll();
	}
	@GetMapping("/{id}")
	public ResultBean getById(@PathVariable("id") Integer id) throws Exception {
		System.out.println("删除操作");
		return employeeService.getById(id);
	}
	@PostMapping("/page")
	public ResultBean page(@RequestBody EmployeeQuery employeeQuery) throws Exception {
		System.out.println("分页操作");
		return employeeService.getByPage(employeeQuery);
	}

}
